package com.lvm.app.task;

import org.junit.Test;
import java.util.UUID;
import java.util.concurrent.*;

public class VideoTaskExecutor extends Thread{


    private final LinkedBlockingQueue<Runnable> taskQueue= new LinkedBlockingQueue<Runnable>();

    private ExecutorService pool;

    public boolean addTask(VideoTask v) throws InterruptedException {
        taskQueue.put(v);
        return true;
    }
    public VideoTaskExecutor(){
        pool = Executors.newFixedThreadPool(5);
        super.start();
    }
    @Override
    public void run() {
        try{
            while (true){
                Runnable task = taskQueue.take();
                pool.execute(task);
            }
        }catch (Exception e){

        }

    }

    @Test
    public void taskTest(){
        VideoTaskExecutor executor = new VideoTaskExecutor();
        for(int i=0;i<20;i++){
            VideoTask v = new VideoTask(null,null);
            v.setTaskId(UUID.randomUUID().toString());
            try{
                executor.addTask(v);

            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }


    }




}
